/*
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package net.javlov.policy;

import java.util.List;
import java.util.Random;

import net.javlov.Option;
import net.javlov.Policy;
import net.javlov.State;
import net.javlov.vf.OptionValues;

/**
 * A policy that doesn't pay attention to the state but selects a random action on every
 * invocation of getAction(State), according to the supplied random number generator.
 * 
 * @author Matthijs Snel
 *
 */
public class RandomPolicy<T> implements Policy<T> {
	
	protected Random rng;
		
	private List<? extends Option<T>> optionPool;
	private int size;
	
	public RandomPolicy(List<? extends Option<T>> optionPool, Random rng) {
		this.optionPool = optionPool;
		size = optionPool.size();
		this.rng = rng;
	}
	
	@Override
	public Option<T> getOption(State<? extends T> s) {
		return optionPool.get(rng.nextInt(size));
	}

	@Override
	public Option<T> getOption(State<? extends T> s, OptionValues qvalues) {
		return optionPool.get(rng.nextInt(size));
	}

	@Override
	public void init() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void reset() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public double[] getOptionProbabilities(State<? extends T> s, OptionValues qvalues) {
		double[] probs = new double[qvalues.size()];
		for ( int i = 0; i < probs.length; i++ )
			probs[i] = 1/probs.length;
		return probs;
	}
}
